package com.sit.estatemanagementserver.controller;

import com.sit.estatemanagementserver.enity.Response;
import com.sit.estatemanagementserver.service.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/work-orders")
public class WorkOrderController {

    @Autowired
    private WorkOrderService workOrderService;

    @GetMapping("/generate")
    public Response<String> generateWorkOrder(@RequestParam String type) {
        String prefix = "";
        switch (type.toLowerCase()) {
            case "repair":
                prefix = "R";
                break;
            case "complaint":
                prefix = "C";
                break;
            case "facility":
                prefix = "F";
                break;
            default:
                return Response.error("无效的工单类型");
        }
        String workOrderId = workOrderService.generateOrderNumber(prefix);
        return Response.success(workOrderId);
    }
}